﻿using SIE.SCADA.ZemtDemo.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SCADA_DAQ.ZEMT.Server
{
    public abstract  class MqMangerBase<T> : IManager, IDisposable where T:new()
    {
        protected PgSqlAccess pgsql;
        public MqMangerBase()
        {
            pgsql = new PgSqlAccess();
        }
        protected RabbitMQHelper mqhelper = new RabbitMQHelper();
        protected bool _stop;
        private static T instance;
        private static object singleton_Lock = new object();
        public static T CreateInstance()
        {
            if (instance == null)
            {
                lock (singleton_Lock)
                {
                    if (instance == null)
                    {
                        instance = new T();
                    }
                }
            }
            return instance;
        }

        public virtual void Start()
        {
            _stop = false;
        }

        public virtual void Stop()
        {
            _stop = true;
        }

        public void Dispose()
        {
            _stop = true;
            mqhelper.Close();
        }
    }
}
